package com.ddwl.common.util;

import java.util.Random;

/**
 * @author Fu Zhaohui
 */
public final class RandomGenerateUtil {

    private static final Random getR = new Random();
    private static final String baseDigits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    private static final int BASE = baseDigits.length();

    public static String getRandomS(int type, int length) {
        StringBuilder sb = new StringBuilder();
        switch (type) {
            case 1:
                for (int i = 0; i < length; i++) {
                    sb.append(getSz());
                }
                break;
            default:
                for (int i = 0; i < length; i++) {
                    int ri = getR.nextInt(2);
                    sb.append(ri == 0 ? getSz() : getZm());
                }
                break;
        }
        return sb.toString();
    }

    private static String getZm() {
        char sSS = (char) (getR.nextInt(26) + 97);
        char sBs = (char) (getR.nextInt(26) + 65);
        char[] sTemp = {sSS, sBs};
        int i = getR.nextInt(2);
        return String.valueOf(sTemp[i]);
    }

    private static String getSz() {
        int getI = getR.nextInt(10) + 48;
        return String.valueOf((char) getI);
    }

    public static String getRandomStr(int length) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = getR.nextInt(BASE);
            sb.append(baseDigits.charAt(number));
        }
        return sb.toString();
    }
}